package FrameWork.PathFinding;

import java.util.ArrayList;
import java.util.List;

public class AStar implements Heuristic {
	private int Hprop = 2;
	
	@Override
	public void findH(Node node, NodeMap nodeMap) {
		int H = (Math.abs(node.getX()-nodeMap.getEndX()) + Math.abs(node.getY()-nodeMap.getEndY()));
		node.setH(H*Hprop + node.getValue());
	}

	@Override
	public List<Node> getCutOffPoint(List<Node> live) {
		if(!live.isEmpty()){
		int H = live.get(0).getH();
		for(Node node:live){
			if(H>node.getH()){
				H = node.getH();
			}
		}
		List<Node> next = new ArrayList<Node>();
		for(Node node:live){
			if(node.getH()==H){
				next.add(node);
			}
		}
		return next;
		}
		return new ArrayList<Node>();
	}

	@Override
	public void setHValue(int HValue) {
		Hprop = HValue;
	}

}
